package commands.customer
{
	import cultu.customer.message.Customer;
	import cultu.customer.message.CustomerScenario;
	import cultu.customer.service.CustomerManager;
	
	import model.Model;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import utils.CultuConstants;
	
	import vo.CustomerVO;
	
	import wizeoo.commands.WIZRemoteCall;
	
	public class CreateCustomerCmd extends WIZRemoteCall
	{
		/**Référence au model*/
		private var mod:Model = Model.getInstance();
		
		/**le customer a créer*/
		public var customer:CustomerVO;
		
		public function CreateCustomerCmd(pCustomer:CustomerVO,pCallback:Function=null)
		{
			super(pCallback);
			customer = pCustomer;
		}
		
		override public function wizExecute():void
		{
			var cm:CustomerManager = new CustomerManager();
			var cs:CustomerScenario = new CustomerScenario();
			
			cm.addEventListener(ResultEvent.RESULT,result,false,0,true);
			cm.addEventListener(FaultEvent.FAULT,fault,false,0,true);
			
			mod.setContext(CultuConstants.CMD_CREATE,customer.srcCustomer);
			
			cm.createCustomer(null,cs,customer.srcCustomer);
		}
		
		override protected function wizResult(data:Object):void
		{
			if(data && data.result)
			{
				customer.srcCustomer = data.result as Customer;
			}
		}
		
		override protected function wizFault(info:Object):void
		{
			trace('unable to create customer');	
		}
	}
}